/*
 * @Author: 哈尔滨大拐 3181845089@qq.com
 * @Date: 2022-08-04 16:38:53
 * @LastEditors: 哈尔滨大拐 3181845089@qq.com
 * @LastEditTime: 2022-08-08 11:20:30
 * @FilePath: \mygit\个人网站\admin\js\main.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*--------------------------------------------------------------
  1. 常用函数封装
--------------------------------------------------------------*/
(function (global) {
  global = global || self;

  const baseUrl = "http://81.70.162.221:3000/";
  axios.defaults.baseURL = baseUrl;

  let myToken = localStorage.getItem("token");
  if (myToken) {
    axios.defaults.headers.common["Authorization"] = myToken; // 将token存在请求头中
  }

  global.imgUrl = function (url) {
    return baseUrl + "/" + url;
  };

  global.getQueryString = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
  };
})(window);
